﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Linq;
using System.Windows;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {
        public void YGRPPOLIST(DataSet db)
        {
            int x = 4, y = 1;
            string VKPPOSTYP = "";
            DataTable dtOutput = new DataTable();
            try
            {
                /*
            <DataGridTextColumn Binding="{Binding Path=VKPLIEFTERM}" Header="交期"  Width="Auto" MinWidth="40"/>
            <DataGridTextColumn Binding="{Binding Path=VKPERLDAT}" Header="实际完成"  Width="Auto" MinWidth="40"/>
            <DataGridTextColumn Binding="{Binding Path=DELAYDAYS}" Header="拖期天数"  Width="Auto" MinWidth="40"/>*/
                #region======Title===========
                exAgent.SetCellValue(3, 1, "类型");
                exAgent.SetCellValue(3, 2, " ");
                exAgent.SetCellValue(3, 3, "PPO");
                exAgent.SetCellValue(3, 4, "接单日期");
                exAgent.SetCellValue(3, 5, "申购单号");
                exAgent.SetCellValue(3, 6, "客户");
                exAgent.SetCellValue(3, 7, "品种");
                exAgent.SetCellValue(3, 8, "色号");
                exAgent.SetCellValue(3, 9, "成份");
                exAgent.SetCellValue(3, 10, "客人色号");
                exAgent.SetCellValue(3, 11, "合同号");
                exAgent.SetCellValue(3, 12, "强力标准");
                exAgent.SetCellValue(3, 13, "捻度标准");
                exAgent.SetCellValue(3, 14, "颜色标准");
                exAgent.SetCellValue(3, 15, "用途");
                exAgent.SetCellValue(3, 16, "数量");
                exAgent.SetCellValue(3, 17, "成纱量");
                exAgent.SetCellValue(3, 18, "已出货");
                exAgent.SetCellValue(3, 19, "库存量");
                exAgent.SetCellValue(3, 20, "单位");
                exAgent.SetCellValue(3, 21, "溢短装");
                exAgent.SetCellValue(3, 22, "价格");
                exAgent.SetCellValue(3, 23, "PUM");
                exAgent.SetCellValue(3, 24, "交期");
                exAgent.SetCellValue(3, 25, "实际完成");
                exAgent.SetCellValue(3, 26, "拖期天数");

                #endregion

                #region=====TableColumns====
                dtOutput.Columns.Add("VKPPOSTYP", typeof(System.String));
                dtOutput.Columns.Add("VKPAUFKRS", typeof(System.String));
                dtOutput.Columns.Add("VKPAUFLFD", typeof(System.String));
                dtOutput.Columns.Add("VKPNEUDAT", typeof(System.String));
                dtOutput.Columns.Add("VKPKDKOMM", typeof(System.String));
                dtOutput.Columns.Add("KDKUNDNA", typeof(System.String));
                dtOutput.Columns.Add("VKPART", typeof(System.String));
                dtOutput.Columns.Add("VKPFARBE", typeof(System.String));
                dtOutput.Columns.Add("VKCOM", typeof(System.String));
                dtOutput.Columns.Add("VKPKDFARBNR", typeof(System.String));
                dtOutput.Columns.Add("VKKBESTNR", typeof(System.String));
                dtOutput.Columns.Add("STRENGTH", typeof(System.String));
                dtOutput.Columns.Add("COLORSTD", typeof(System.String));
                dtOutput.Columns.Add("TWIST", typeof(System.String));
                dtOutput.Columns.Add("VAAPRGR", typeof(System.String));
                dtOutput.Columns.Add("VKPMENGE1", typeof(System.String));
                dtOutput.Columns.Add("VKPZUGET", typeof(System.String));
                dtOutput.Columns.Add("VKPFREIGE", typeof(System.String));
                dtOutput.Columns.Add("STOCKQTY", typeof(System.String));
                dtOutput.Columns.Add("VKPMEEH", typeof(System.String));
                dtOutput.Columns.Add("OVERSHORT", typeof(System.String));
                dtOutput.Columns.Add("VKPPREIS", typeof(System.String));
                dtOutput.Columns.Add("PUM", typeof(System.String));
                dtOutput.Columns.Add("VKPLIEFTERM", typeof(System.String));
                dtOutput.Columns.Add("VKPERLDAT", typeof(System.String));
                dtOutput.Columns.Add("DELAYDAYS", typeof(System.String));
                #endregion

                #region======ConvertData===
                var qGW = from GW in db.Tables["VKPOS"].AsEnumerable()
                          group GW by new
                          {
                              PT = GW["VKPPOSTYP"].ToString(),
                          }
                              into g
                              select new
                              {
                                  KEY = g.Key,
                              };
                foreach (var GW in qGW)
                {
                    VKPPOSTYP = GW.KEY.PT;
                    exAgent.SetCurrentSheet("YGRPPOLIST");
                    exAgent.CopySheet("分类"+VKPPOSTYP.Trim());
                    DataRow[] rows = db.Tables["VKPOS"].Select("VKPPOSTYP='" + VKPPOSTYP + "'");
                    DataTable dtSoruce = rows.CopyToDataTable();
                    dtOutput.Clear();
                    dtOutput.Merge(dtSoruce, false, MissingSchemaAction.Ignore);
                    foreach (DataRow rx in dtOutput.Rows)
                    {
                    }
                #endregion

                    #region====Excel==========
                    int count = dtOutput.Rows.Count;
                    exAgent.RangeCopy(4, 50, 5, 4 + count);
                    exAgent.DataTableToExcel(dtOutput, x, 1); 
                    exAgent.SetCellValue(1, 1, 1);
                    exAgent.BatchConvert2Number(4, 16, count + 3, 19);
                    exAgent.BatchConvert2Number(4, 22, count + 3, 22);
                    #endregion
                }
                exAgent.DeleteSheet("YGRPPOLIST");
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                EventDispatcher.Instance.RaiseStatus("完成", StatusEventType.StopProgress);
            }
            
        }

    }
}